<template>
  <!-- 根组件 -->

  <el-container class="home-body">
    <el-header>
      <div class="right">
        <img src="../assets/img/logo.png" alt />
        <span>电商管理系统</span>
      </div>
      <el-button type="primary" icon="el-icon-switch-button" @click="exit">退出</el-button>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu unique-opened class="el-menu-vertical-demo" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b" router>
          <el-submenu :index=" item.id+ ''" v-for="item of menuList" :key="item.id">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item :index=" '/'+ subitem.path + '' " v-for="subitem of item.children" :key="subitem.id">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{subitem.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: '',
  components: {},

  data () {
    return {
      menuList: []
    }
  },
  created () {
    this.getMenuList()
  },
  methods: {
    //   退出系统
    exit () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    async getMenuList () {
      const { data: listMenu } = await this.axios.get('menus')
      this.menuList = listMenu.data
    }
  }
}
</script>

<style scoped  lang='less'>
.home-body {
  height: 100%;
  overflow: auto;
}

.el-header {
  background-color: #0f90d2;
  color: #333;
  text-align: center;
  line-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .right {
    display: flex;
    align-items: center;
    font-size: 20px;
    color: #ffffff;
    letter-spacing: 5px;
    img {
      width: 50px;
      height: 50px;
      margin-right: 20px;
    }
  }
}

.el-aside {
  background-color: #545c64;
  color: #333;
  line-height: 200px;
  .el-menu {
    border-right: none;
  }
}

.el-main {
  background-color: #fefefe;
  color: #333;
}

body > .el-container {
  margin-bottom: 40px;
}
</style>
